/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.UserPoDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class UserPoDaoImpl extends BaseDaoImpl implements UserPoDao {
	public List getList(long userId) {
		String sql = "from com.minierp.model.UserPo p where p.userId=" + userId;
		return this.getHibernateTemplate().find(sql);
	}

	public List getListByStaffer(long stafferId, String poType) {
		String sql = "select ut from  com.minierp.model.User u ,com.minierp.model.UserPo ut where ut.userId=u.id and ut.poType=:poType and u.stafferId="
				+ stafferId
				+ " and u.enabled=\'Y\'"
				+ " and (u.useValidity=\'N\' or u.useValidity=\'Y\' and u.validity>:validity)";
		Session sess = null;

		List arg7;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			q.setString("poType", poType);
			q.setDate("validity", new Date());
			arg7 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg7;
	}

	public int delete(final long id) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.UserPo where id=:id";
						return new Integer(session.createQuery(hql)
								.setLong("id", id).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}
}